package com.rongxun.common.base;

import android.content.Context;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;


/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/21 14:55
 * 描述
 */

public class HomeFragVpAdapter extends FragmentPagerAdapter {

    private Fragment[] fragments;
    private Context    context;
    private String[]   fnames;

    public HomeFragVpAdapter(FragmentManager fm, Context context, String[] fnames) {
        super(fm);
        this.context = context;
        this.fnames = fnames;
        if(fnames != null){
            fragments = new Fragment[fnames.length];
        }
    }

    @Override
    public Fragment getItem(int position) {
        if (fragments[position] == null) {
            fragments[position] = Fragment.instantiate(context,fnames[position]);
        }
        return fragments[position];
    }

    @Override
    public int getCount() {
        if(fnames == null){
            return 0;
        }
        return fnames.length;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }
}

